public class WBUpdateWeiboURL {

    public WBContent__c content {get;set;}
        
    public WBUpdateWeiboURL( ApexPages.Standardcontroller stdControl ){
          content = [SELECT mid__c , id__c , Weibo_URL__c,User__c FROM WBContent__c WHERE ID=:stdControl.getId()];
    }
    
    public String getMid(){
        return content.id__c;
    }
        
    public String getQueryWeiboURL(){
        
        String wbid = content.mid__c ;
        String result = content.Weibo_URL__c;
        
        if( wbid!=null && wbid.length()>0 && content.id__c==null ){
        
            WB_OpenApi.WB_Statuses_QueryMid_ById_In queryIn = new WB_OpenApi.WB_Statuses_QueryMid_ById_In();
            WB_OpenApi.WB_Statuses_QueryMid_ById_Out queryOut = new WB_OpenApi.WB_Statuses_QueryMid_ById_Out();
            queryIn.id = wbid;
            String jsonResult = queryIn.toRequestURL();
           
            if( jsonResult.startsWith('{"error') ){
                 result = jsonResult;
            }else{
                queryOut = queryOut.parse(jsonResult);
                String queryMid = queryOut.mid;
                result += queryMid ;
                
                if( queryMid !=null && queryMid.length() > 0  ){
                    content.id__c = queryMid;
                }
                
            }  
        }else{
            result = content.Weibo_URL__c;
        }
        
        return result;
    }
    
    public void updateWeiboMid(){
        if( content.id__c!=null ){
            update content;
        }
    
    }

}